﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Razor.Runtime.TagHelpers;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace WebApplication1.TagHelpers
{
    // You may need to install the Microsoft.AspNetCore.Razor.Runtime package into your project
    [HtmlTargetElement("input", Attributes = "input-type", ParentTag = "div")] //针对已有的html元素input,属性:input-type,ParentTag:父标签为div
    public class ParentTagHelper : TagHelper
    {
        public string InputType { get; set; }

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var preElement = new TagBuilder("div");
            preElement.AddCssClass("input-group-addon");
            var postElement = new TagBuilder("div");
            postElement.AddCssClass("input-group-addon");


            switch (InputType)
            {
                case "User":
                    var glyphiconUser = new TagBuilder("i");
                    glyphiconUser.AddCssClass("glyphicon glyphicon-user");
                    preElement.InnerHtml.AppendHtml(glyphiconUser);
                    break;
                case "Pencil":
                    var glyphiconPencil = new TagBuilder("i");
                    glyphiconPencil.AddCssClass("glyphicon glyphicon-pencil");
                    preElement.InnerHtml.AppendHtml(glyphiconPencil);
                    break;
                default:
                    break;
            }

            output.PreElement.SetHtmlContent(preElement);
            output.PostElement.SetHtmlContent(postElement);
        }
    }
}
